<p>While it is technically correct to assign to parameters from within method bodies, it is better to use temporary variables to store intermediate results.</p>
<p>This rule will typically detect cases where a constructor parameter is assigned to itself instead of a field of the same name, i.e. when <code>this</code> was forgotten.</p>
<p>Allowing parameters to be assigned to also reduces the code readability as developers will not be able to know whether the original parameter or some temporary variable is being accessed without going through the whole method.</p>
<p>Moreover, some developers might also expect assignments of method parameters to be visible from callers, which is not the case and can confuse them.</p>
<p>All parameters should be treated as <code>final</code>.</p>
<h2>Noncompliant Code Example</h2>

<pre>
class MyClass {
  public String name;

  public MyClass(String name) {
    name = name;                    // Noncompliant - useless identity assignment
  }

  public int add(int a, int b) {
    a = a + b;                      // Noncompliant

    /* additional logic */

    return a;                       // Seems like the parameter is returned as is, what is the point?
  }

  public static void main(String[] args) {
    MyClass foo = new MyClass();
    int a = 40;
    int b = 2;
    foo.add(a, b);                  // Variable "a" will still hold 40 after this call
  }
}
</pre>
<h2>Compliant Solution</h2>

<pre>
class MyClass {
  public String name;

  public MyClass(String name) {
    this.name = name;               // Compliant
  }

  public int add(int a, int b) {
    return a + b;                   // Compliant
  }

  public static void main(String[] args) {
    MyClass foo = new MyClass();
    int a = 40;
    int b = 2;
    foo.add(a, b);
  }
}
</pre>
<h2>See</h2>

<ul>
<li> MISRA C:2012, 17.8 - A function parameter should not be modified</li>
</ul>

